#define EPSILON.001
#define MAX_DIST 200.

vec2 fixUV(vec2 cood){
  return(2.*cood.xy-iResolution.xy)/min(iResolution.x,iResolution.y);
}

mat3 setCamera(vec3 ro,vec3 target,float cr){
  vec3 cw=normalize(target-ro);
  vec3 cp=vec3(sin(cr),cos(cr),0.);
  vec3 cu=normalize(cross(cw,cp));
  vec3 cv=normalize(cross(cu,cw));
  return mat3(cu,cv,cw);
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
  vec2 uv=fixUV(fragCoord);
  // 设置摄像头看的位置
  vec3 target=vec3(0,4,0);
  float rad=10.;
  float an=iTime*.5;
  // float an=0.;
  vec3 ro=vec3(sin(an)*rad,2,cos(an)*rad);
  mat3 cam=setCamera(ro,target,0.);
  // 设置视线焦距
  float fl=2.5;
  vec3 rd=normalize(cam*vec3(uv,fl));
  
  // 制作太阳
  vec3 sunLight=normalize(vec3(0.,.4,-1.));
  float sundot=clamp(dot(rd,sunLight),0.,1.);
  
  // 制作天空
  vec3 color=vec3(.3,.5,.85)-rd.y*rd.y*.5;
  color=mix(color,.85*vec3(.7,.75,.85),pow(1.-max(rd.y,0.),4.));
  
  color+=.25*vec3(1.,.7,.4)*pow(sundot,5.);
  color+=.25*vec3(1.,.8,.6)*pow(sundot,64.);
  color+=.2*vec3(1.,.8,.6)*pow(sundot,512.);
  color=mix(color,.68*vec3(.4,.65,1.),pow(1.-max(rd.y,0.),16.));
  fragColor=vec4(color,1.);
}